import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-07-08
 * Time: 21:28
 */
public class MinStack {

    Stack<Integer> numS;
    Stack<Integer> minNum;

    public MinStack() {
        this.numS = new Stack<>();
        this.minNum = new Stack<>();
    }

    public void push(int val) {
        numS.push(val);
        if(minNum.empty()) {
            minNum.push(val);
        }else {
            if(val <= minNum.peek()) {
                minNum.push(val);
            }
        }
    }

    public void pop() {
        if (!numS.empty()) {
            int val = numS.pop();
            if (val == minNum.peek()) {
                minNum.pop();
            }
        }
    }

    public int top() {
        return numS.peek();
    }

    public int getMin() {
        return minNum.peek();
    }
}
